package xyz.ddlnt.management.mg.controller;

import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.constant.HttpConstants;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.entity.AdminInfo;
import xyz.ddlnt.servicemgclient.client.AdminFeignClient;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 15:57
 */
@Slf4j
@Tag(name = "管理接口测试")
@RestController
@RequestMapping(("/admin"))
public class AdminController {

    @Resource
    private AdminFeignClient adminFeignClient;

    @Operation(summary = "管理员登录")
    @PostMapping("login")
    public Result<String> login(@RequestBody AdminInfo adminInfo) {
        return adminFeignClient.login(adminInfo);
    }
    @Operation(summary = "管理员登出")
    @GetMapping("/logout")
    public Result<Boolean> logout(HttpServletRequest request) {
        String satoken = request.getHeader(HttpConstants.SATOKEN);
        log.error("satoken"+satoken);
        StpUtil.logout(StpUtil.getLoginIdByToken(satoken));
        return Result.success();
    }

    @Operation(summary = "管理员注册")
    @PostMapping("register")
    public Result<Boolean> register(@RequestBody AdminInfo adminInfo) {
        return adminFeignClient.register(adminInfo);
    }
}
